package com.yoga.service.impl;


import com.yoga.entity.YogaUser;
import com.yoga.entity.YogaUserExample;
import com.yoga.mapper.YogaUserDao;
import com.yoga.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class LoginServiceImpl implements LoginService {
    @Autowired
    private YogaUserDao yogaUserDao;

    @Override
    public YogaUser login(YogaUser yogaUser) {
        YogaUserExample example = new YogaUserExample();
        YogaUserExample.Criteria criteria = example.createCriteria();
        criteria.andPhoneEqualTo(yogaUser.getPhone());
        criteria.andUpwdEqualTo(yogaUser.getUpwd());
        List<YogaUser> yogaUserinfoList = yogaUserDao.selectByExample(example);
        return yogaUserinfoList.size()==0?null:yogaUserinfoList.get(0);
    }

    @Override
    public YogaUser logins(String phone) {
        YogaUserExample example = new YogaUserExample();
        YogaUserExample.Criteria criteria = example.createCriteria();
        criteria.andPhoneEqualTo(phone);
        List<YogaUser> yogaUserList = yogaUserDao.selectByExample(example);
        return yogaUserList.size()==0?null:yogaUserList.get(0);
    }

    @Override
    public boolean update(Integer uid, String upwd) {
        YogaUser yogaUser = new YogaUser();
        yogaUser.setUid(uid);
        yogaUser.setUpwd(upwd);
        int i = yogaUserDao.updateByPrimaryKeySelective(yogaUser);
        return i>0?true:false;
    }

    @Override
    public YogaUser loginCode(String phone) {
        YogaUserExample example = new YogaUserExample();
        YogaUserExample.Criteria criteria = example.createCriteria();
        criteria.andPhoneEqualTo(phone);
        List<YogaUser> yogaUsers = yogaUserDao.selectByExample(example);
        return yogaUsers.size()==0?null:yogaUsers.get(0);
    }

    @Override
    public boolean save(YogaUser yogaUser) {
        return false;
    }
}
